<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns whether phar extension supports compression using either zlib or bzip2</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="phar.buildfromiterator.html">« Phar::buildFromIterator</a></li>
      <li style="float: right;"><a href="phar.canwrite.html">Phar::canWrite »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.phar.html">Phar</a></li>
    <li>Returns whether phar extension supports compression using either zlib or bzip2</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="phar.cancompress" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Phar::canCompress</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL phar &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Phar::canCompress</span> &mdash; <span class="dc-title">Returns whether phar extension supports compression using either zlib or bzip2</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-phar.cancompress-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>Phar::canCompress</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$compression</code><span class="initializer"> = 0</span></span>): <span class="type">bool</span></div>


  <p class="para rdfs-comment">
   This should be used to test whether compression is possible prior to
   loading a phar archive containing compressed files.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-phar.cancompress-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">compression</code></dt>

     <dd>

      <p class="para">
       Either <code class="literal">Phar::GZ</code> or <code class="literal">Phar::BZ2</code> can be
       used to test whether compression is possible with a specific compression
       algorithm (zlib or bzip2).
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-phar.cancompress-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <strong><code>true</code></strong> if compression/decompression is available, <strong><code>false</code></strong> if not.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-phar.cancompress-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-721">
    <p><strong>示例 #1 A <span class="function"><strong>Phar::canCompress()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">canCompress</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar://compressedphar.phar/internal/file.txt'</span><span style="color: #007700">);<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'no&nbsp;compression&nbsp;available'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-phar.cancompress-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="pharfileinfo.getcompressedsize.html" class="function" rel="rdfs-seeAlso">PharFileInfo::getCompressedSize()</a> - Returns the actual size of the file (with compression) inside the Phar archive</span></li>
    <li class="member"><span class="function"><a href="pharfileinfo.iscompressed.html" class="function" rel="rdfs-seeAlso">PharFileInfo::isCompressed()</a> - Returns whether the entry is compressed</span></li>
    <li class="member"><span class="function"><a href="pharfileinfo.compress.html" class="function" rel="rdfs-seeAlso">PharFileInfo::compress()</a> - Compresses the current Phar entry with either zlib or bzip2 compression</span></li>
    <li class="member"><span class="function"><a href="pharfileinfo.decompress.html" class="function" rel="rdfs-seeAlso">PharFileInfo::decompress()</a> - Decompresses the current Phar entry within the phar</span></li>
    <li class="member"><span class="function"><a href="phar.iscompressed.html" class="function" rel="rdfs-seeAlso">Phar::isCompressed()</a> - Returns Phar::GZ or PHAR::BZ2 if the entire phar archive is compressed (.tar.gz/tar.bz and so on)</span></li>
    <li class="member"><span class="function"><a href="phar.compressfiles.html" class="function" rel="rdfs-seeAlso">Phar::compressFiles()</a> - Compresses all files in the current Phar archive</span></li>
    <li class="member"><span class="function"><a href="phar.decompressfiles.html" class="function" rel="rdfs-seeAlso">Phar::decompressFiles()</a> - Decompresses all files in the current Phar archive</span></li>
    <li class="member"><span class="function"><a href="phar.getsupportedcompression.html" class="function" rel="rdfs-seeAlso">Phar::getSupportedCompression()</a> - Return array of supported compression algorithms</span></li>
    <li class="member"><span class="function"><a href="phar.converttoexecutable.html" class="function" rel="rdfs-seeAlso">Phar::convertToExecutable()</a> - Convert a phar archive to another executable phar archive file format</span></li>
    <li class="member"><span class="function"><a href="phar.converttodata.html" class="function" rel="rdfs-seeAlso">Phar::convertToData()</a> - Convert a phar archive to a non-executable tar or zip file</span></li>
   </ul>
  </p>
 </div>



</div></div></div></body></html>